<template>
  <!--   处置弹窗  -->
  <el-dialog
    class="dia-style"
    title="发起工单"
    :visible.sync="open"
    width="60%"
    :close-on-click-modal="false"
    @close="cancel">
    <HkForm
      ref="hkFormRef"
      label-width="140"
      :form-labels="formObj.formLabels"
      :rules="formObj.formRules"
      :data="formData"
      :dict-list="formObj.dictList"
      :btn-hidden="true" />
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="submitForm">提 交</el-button>
      <el-button @click="cancel">取 消</el-button>
    </div>
  </el-dialog>
</template>

<script>
// import HkForm from '@/components/HK-Form'
// import { getFlowsList, putIncidentOrder } from '@/api/dispose/launchWorkOrder'
// import { parseTime } from '@/utils/hongke.js'
export default {
  // components: { HkForm },
  props: {},
  data() {
    return {
      open: false,
      formObj: {
        formLabels: [
          { label: '流程', field: 'besFlowsId', type: 'select', list: 'eventCauseList', span: 24 },
          { label: '标题', field: 'title', type: 'input', span: 24 },
          {
            label: '期望完成时间',
            field: 'expectTime',
            type: 'dateTime',
            span: 24,
          },
          {
            label: '发起事由',
            field: 'causeInitiation',
            type: 'textarea',
            span: 24,
            attrs: {
              rows: 5,
              placeholder: '发起事由',
            },
          },
        ],
        formRules: {
          besFlowsId: [{ required: true, message: '请选择', trigger: 'blur' }],
          title: [{ required: true, message: '请选择', trigger: 'blur' }],
          expectTime: [{ required: true, message: '请选择', trigger: 'blur' }],
          causeInitiation: [{ required: true, message: '请输入发起事由', trigger: 'blur' }],
        },
        dictList: {
          eventCauseList: [],
        },
      },
      formData: {},
      incidentId: [],
    }
  },
  created() {},
  methods: {
    show(row) {
      this.open = true
      this.getDictList()
      this.incidentId = row.id
      this.formData = {
        title: `'${row.metrics_name} ${row.logtime}'处置工单`,
      }
    },
    getDictList() {
      getFlowsList()
        .then((res) => {
          //   事件成因
          this.formObj.dictList.eventCauseList = res.map((i) => {
            return { label: i.name, value: i.id }
          })
        })
        .catch((error) => {
          console.log(error)
        })
    },
    submitForm() {
      this.$refs.hkFormRef.handleFormSubmit('formLabels').then((res) => {
        res.expectTime = parseTime(res.expectTime)
        putIncidentOrder({
          incidentId: this.incidentId,
          ...res,
        }).then((res) => {
          this.$message.success('提交成功')
          this.$emit('handleSubmit')
          this.cancel()
        })
      })
    },
    cancel() {
      this.$refs.hkFormRef.resetForm('formLabels')

      this.open = false
    },
  },
}
</script>

<style scoped></style>
